#!/bin/sh
cd `dirname $0`
###################
source /etc/profile
source /root/.bash_profile
##################
#因为能源model库用到了app的这个地区和枚举表数据源，放到学年学期之前
BASIC="
basic_area_info.sh
basic_enum_info.sh
"

#日志路径
function getRunLogPath(){
    datetime=$(date --date "0 days ago" +%Y%m%d)
    if [ ! -d "./logs" ];then
        mkdir ./logs
    fi
    LOG_RUN_PATH=/root/etl/SXNYZY/Timing/modelToApp/logs/$0_${datetime}.log
}
function doconmand(){
    start=$(date +%s)
    #读取文件的每一行
	for comand in ${comands}
	do
		ps -ef|grep $comand|grep -v grep|cut -c 9-15|xargs kill -9
	    sh $comand
	    end=$(date +%s)
		 if [ $? -eq 0 ]; then
	    	echo " $comand succeed>>>  耗时$(( $end - $start ))s " >>  ${LOG_RUN_PATH} 2>&1
		 else
		    echo " $comand failed>>>  耗时$(( $end - $start ))s "  >>  ${LOG_RUN_PATH} 2>&1;
		    echo " ## sh $comand 脚本执行错误，退出命令  exit 1  ##"  >>  ${LOG_RUN_PATH} 2>&1;
		    exit 1;
		 fi

	done
	end=$(date +%s)
	echo " 耗时$(( $end - $start ))s" >>  ${LOG_RUN_PATH} 2>&1
	#删除脚本执行过程中产生的Java文件
	rm -rf *.java
}
#basic层面其他app
function BASIC() {
   echo "-------basic层面其他app开始全部执行--------" >>  ${LOG_RUN_PATH} 2>&1;
   comands=${BASIC[*]}
   doconmand >>  ${LOG_RUN_PATH} 2>&1;
}


getRunLogPath
CURRENTPATH_COLLEGE=/root/etl/SXNYZY/diagnosis
comands=()

if [ $? -eq 0 ]; then
	cd  ${CURRENTPATH_COLLEGE}/basic/app
	BASIC
fi


echo "*********所有脚本执行完毕*********" >>  ${LOG_RUN_PATH} 2>&1